package com.youlai.quarkus.system.common.util;

import com.alibaba.fastjson2.util.ParameterizedTypeImpl;

import java.lang.reflect.Type;

/**
 * @author csp 2024-08-30
 */
public class FastJson2Util {

    public static Type buildType(Type... types) {
        ParameterizedTypeImpl beforeType = null;
        if (types != null && types.length > 0) {
            if (types.length == 1) {
                return new ParameterizedTypeImpl(new Type[]{null}, (Type)null, types[0]);
            }

            for(int i = types.length - 1; i > 0; --i) {
                beforeType = new ParameterizedTypeImpl(new Type[]{(Type)(beforeType == null ? types[i] : beforeType)}, (Type)null, types[i - 1]);
            }
        }

        return beforeType;
    }

}
